home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / clptick.zip / TICKER.PRG < prev    next >
Text File  |  1993-04-07  |  3KB  |  127 lines

  1. /*
  2. **    Program..: Ticker.prg
  3. **    Author...: Brenton Farmer
  4. **    Date.....: 10/10/91
  5. **
  6. **    Purpose..: Set of routines to attach a Clipper function to the
  7. **            system clock interrupt int 8.
  8. **
  9. */
  10. #include "inkey.ch"
  11. #define TRUE  .T.
  12. #define FALSE .F.
  13.  
  14. Static bFunction
  15.  
  16. #define _TEST
  17. #ifdef _TEST
  18. Function Main()
  19. Local cString  := "Now Is the Time"
  20. Local cString2 := "Bla Bla Bla    "
  21.  
  22.     cls
  23.     Ticker( 1, "ShowTime")
  24.     setkey( K_ALT_T, {|| HotKeyTest()})
  25.  
  26.     @10,00 say " Type some stuff:" get cString
  27.     @11,00 say " Type some more :" get cString2
  28.     read
  29.  
  30.     setkey( K_ALT_T)
  31.     Ticker( 0)
  32.  
  33. Return ( NIL)
  34.  
  35. Function ShowTime()
  36. Local nRow, nCol, nCursor
  37.  
  38.     nCursor := setcursor( 0)
  39.     nRow := row()
  40.     nCol := col()
  41.     DevPos( 00,70)
  42.     DevOut( time())
  43.     setpos( nRow, nCol)
  44.     setcursor( nCursor)
  45.  
  46. Return ( NIL)
  47.  
  48. Function HotKeyTest()
  49. Local nRow, nCol, nCursor
  50.  
  51.     nCursor := setcursor( 0)
  52.     nRow := row()
  53.     nCol := col()
  54.     DevPos( 00,70)
  55.     DevOut( time())
  56.     setpos( nRow, nCol)
  57.     setcursor( nCursor)
  58.  
  59. Return ( NIL)
  60.  
  61. #endif
  62.  
  63.  
  64. /*
  65. **    Void Ticker( nTime, cUserFunc)
  66. **
  67. ** Attach/UnAttach a Clipper function to the system time interrupt.
  68. **
  69. **    If the function was called with nTime and cUserFunc values attempt
  70. **    to attach ( cUserFunc) to the system timer so that it is executed
  71. ** every nTime seconds.  The system timer is hit 18.2 times ( ticks)
  72. ** so nTime must be converted into ticks ( int( nTime * 18.2)).  If
  73. ** ticker() is called without parameters and we have previously attached
  74. ** a function unattach it and restore the original int 8 interrupt
  75. ** vector.
  76. **
  77. ** Arguments:
  78. ** nTime            = Time interval to call ( cUserFunc) expressed in seconds.
  79. **    cUserFunc    = Name of Clipper function to execute every nTime seconds
  80. **
  81. */
  82. Function Ticker( nTime, cUserFunc)
  83. Static lActive  := FALSE
  84.  
  85.     /*
  86.     ** If we have previously redirected the int 8 interrupt vector to our
  87.     ** own routine restore it to its original value.
  88.     */  
  89.     if lActive                     
  90.         C10ckSet( 0)             
  91.         lActive := FALSE
  92.     endif
  93.  
  94.     /*
  95.     **    If the ticker() was called with nTime and cUserFunc values attempt
  96.     **    to attach ( cUserFunc) to the system timer.  Do the following:
  97.     **
  98.     ** 1.  Ensure that ( cUserFunc) has been linked in.
  99.     ** 2.  Compile cUserFunc into code block bFunction in order to
  100.     **     cut down runtime overhead from within C10ckEval().
  101.     ** 3.  Convert nTime into timer ticks and call the C C10ckSet() function.
  102.     **    4.  Set the lActive flag true.
  103.     */
  104.     if ( nTime != NIL .and. cUserFunc != NIL)
  105.         if !( type( alltrim( cUserFunc)+"()") == "U") // is ( cUserFunc) linked
  106.             bFunction := &("{||" + cUserFunc + "()}")     // Yes
  107.             eval( bFunction)
  108.             C10ckSet( int( nTime * 18.2))
  109.             lActive := TRUE
  110.         endif
  111.     endif
  112.  
  113. Return ( NIL)
  114.  
  115.  
  116. /*
  117. **    C10ckEval()
  118. **
  119. **    Clock evaluation routine called from our C code int 8 isr routine
  120. **    C10ckISR() in tickerc.c.  Evaluate the code block bFunction which
  121. ** was defined in Ticker().
  122. */
  123. Function _C10ckEval
  124.     eval( bFunction)
  125. Return ( NIL)
  126.  
  127.